package com.topcheer.provider.common.config;

import com.topcheer.common.auth.context.BaseContextHandler;
import com.topcheer.common.base.CommonConstants;
import com.topcheer.common.base.util.ObjectUtil;
import com.topcheer.common.datasource.dynamic.DataSourceKeyBuilder;
import org.springframework.stereotype.Component;

/**
 * @author xutao
 * @Package com.example.baseline.common.config
 * @Description: ${todo}
 * @date 2020/4/3 15:49
 */
@Component
public class SimpleDataSourceKeyBuilder implements DataSourceKeyBuilder {


    @Override
    public String builder(String dataSourceType) {
        Object o = BaseContextHandler.get(CommonConstants.ORG_ID);
        Long orgId = ObjectUtil.getValue(o, Long.class);
        if(orgId != null){
            return orgId.toString();
        }else {
            return CommonConstants.PRIMARY;
        }
    }
}
